from collections import defaultdict


def solve(strs):
    d = defaultdict(list)
    for s in strs:
        d["".join(sorted(s))].append(s)

    return list(d.values())


if __name__ == "__main__":
    strs = ["eat", "tea", "tan", "ate", "nat", "bat"]
    print(solve(strs))
